/**
 * 
 */
package cn.sqsoft.springresearch.beans.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

import cn.sqsoft.springresearch.beans.AdminManage;
import cn.sqsoft.springresearch.dal.IRoleDAO;
import cn.sqsoft.springresearch.dal.dataobject.RoleDO;

/**
 * @author 75-sq
 * 
 */
public class AdminManageImpl implements AdminManage {
	
	protected static Log log = LogFactory.getLog(AdminManageImpl.class);
	private TransactionTemplate transactionTemplate;
	
	
	
	
	private IRoleDAO roleDAO;
	
	public IRoleDAO getRoleDAO() {
		return roleDAO;
	}

	public void setRoleDAO(IRoleDAO roleDAO) {
		this.roleDAO = roleDAO;
	}
	
	public List loadAdminList() {
		List<String> l = new ArrayList<String>();
		l.add("1");
		l.add("2");
		return l;
	}

	public long insert() {
		Object result = transactionTemplate.execute(new TransactionCallback() {
		    public Object doInTransaction(TransactionStatus status) {
		    	RoleDO roleDO = new RoleDO();
				roleDO.setDescription("test8");
				roleDO.setName("testname8");	
				//App.changeSet(roleDO);	
				
				return roleDAO.insert(roleDO);
				
		        //return resultOfUpdateOperation2();
		    }
		});	
		System.out.println(((Long)result).longValue());
		
		return ((Long)result).longValue();
	}
	
	

	public TransactionTemplate getTransactionTemplate() {
		return transactionTemplate;
	}

	public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
		this.transactionTemplate = transactionTemplate;
	}

	public void update() {
		transactionTemplate.execute(new TransactionCallbackWithoutResult() {
		    protected void doInTransactionWithoutResult(TransactionStatus status) {
		        //updateOperation1();
		        //updateOperation2();
		    }
		});		
	}

	

}
